package com.yungu.swift.admin.route.common;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.base.CurrentUser;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.admin.AdminParam;
import com.yungu.swift.system.sys.model.dto.SysPointSiteCompanyDto;
import com.yungu.swift.system.sys.model.dto.SysPointSiteDto;
import com.yungu.swift.system.sys.service.SysPointSiteCompanyService;
import com.yungu.swift.system.sys.service.SysPointSiteService;
import com.yungu.swift.utils.MapUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: xiuyin.cui@joymo.tech
 * @Date: 2021/4/1 22:08
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/admin/v1/common/business/pointSite")
@Api(value = "【通用服务】", tags = "系统业务类公共接口")
public class PointSiteAdmin {

    @Reference
    private SysPointSiteService sysPointSiteService;
    @Reference
    private SysPointSiteCompanyService sysPointSiteCompanyService;


    @RequestMapping(value = "/allByOrganization", method = RequestMethod.GET)
    @ApiOperation(value = "根据代理信息获取全量起终点数据", httpMethod = "GET")
    public ResponseData<List<SysPointSiteDto>> allWayByOrganization(
            @ApiParam(value = "代理uuid（企业管理时传）") @RequestParam(required = false) String agentUuid,
            @CurrentUser AdminParam adminParam) {
        Map<String, Object> build = MapUtils.build(4);
        build.put("appid", adminParam.getAppid());
        build.put("adminAgentUuid", agentUuid);
        build.put("userAgentUuid", adminParam.getUserAgentUuid());
        build.put("userCompanyUuid", adminParam.getUserCompanyUuid());
        return sysPointSiteService.allByOrganization(build);
    }

    @RequestMapping(value = "/existByOrganization", method = RequestMethod.GET)
    @ApiOperation(value = "根据代理（或公司）信息获取已开通起终点数据", httpMethod = "GET")
    public ResponseData<List<SysPointSiteCompanyDto>> wayByOrganization(@RequestParam String organizationUuid) {
        return sysPointSiteCompanyService.listPointSiteByOrganization(organizationUuid);
    }
}
